﻿using Microsoft.Win32;

namespace unTroublemakerUI
{
    public class Settings
    {
        const string RegistryPath = "Software\\unTroublemaker";

        protected RegistryKey GetKey()
        {
            var key = Registry.CurrentUser.OpenSubKey(RegistryPath, true);
            if (key == null)
                return Registry.CurrentUser.CreateSubKey(RegistryPath);

            return key;
        }

        public string Get(string name)
        {
            using (var key = GetKey())
                return key.GetValue(name) as string;
        }

        public void Remove(string name)
        {
            using(var key = GetKey())
                key.DeleteValue(name, false);
        }

        public void Save(string name, string value)
        {
            using(var key = GetKey())
                key.SetValue(name, value, RegistryValueKind.String);
        }
    }
}
